package org.huawei260.OD260;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @Auther: qingle
 * @Date: 2024/8/21-23:58
 * @Description:
 *
 *
 * @version: 1.0
 */



public class O0014_单词接龙 {

	private static String longestWordChain = "";

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int N = sc.nextInt();

		String[] res = new String[N];
		for (int i = 0; i < N; i++) {
			res[i] = sc.nextLine();
		}

		findLongestWordChain(k, res,  new HashSet<>(), "");

	}
	private static void findLongestWordChain(int index, String[] words, Set<Integer> visited, String currentWordChain) {
		if (currentWordChain.length() > longestWordChain.length()) {
			longestWordChain = currentWordChain;
		}

		String currentWord = words[index];
		visited.add(index);

		for (int i = 0; i < words.length; i++) {
			if (!visited.contains(i) && currentWord.charAt(currentWord.length() - 1) == words[i].charAt(0)) {
				String newWordChain = currentWordChain + words[i];
				findLongestWordChain(i, words, new HashSet<>(visited), newWordChain);
			}
		}

		visited.remove(index);
	}
}
